$(function () {
    $.extend({
        myToast: function (options) {
            var $toast = $('#toast');
            if ($toast.length) {
                if ($toast.css('display') !== 'none') { return }
                $toast.remove();
            }
            var htm = '<div id="toast" style="display: none;">' +
                '<div class="weui-mask_transparent"></div>' +
                '<div class="weui-toast">';
            var text = options.content;
            switch (options.type) {
                case 'success':
                    htm += '<i class="weui-icon-success-no-circle weui-icon_toast"></i>'
                    if (!text) {
                        text = '已完成'
                    }
                    break;
                case 'load':
                    htm += '<i class="weui-primary-loading weui-icon_toast"></i>'
                    if (!text) {
                        text = '加载中...'
                    }
                    break;
                case 'error':
                case 'waring':
                    htm += '<i class="weui-icon-warn weui-icon_toast"></i>'
                    if (!text) {
                        text = '操作错误'
                    }
                    break;
                default:
                    break;
            }
            htm += '<p class="weui-toast__content">' + text + '</p>'
            htm += '</div></div>';
            $('body').append(htm);
            $toast = $('#toast');
            $toast.fadeIn(100);
            setTimeout(() => {
                $toast.fadeOut(100);
                if (options.callback) {
                    options.callback()
                }
            }, options.duration || 3000);
        },
    });
});
